---
title: Reddit
sidebarTitle: Reddit
---

In this section, we present how to connect Reddit to MindsDB.

[Reddit](https://www.reddit.com/) is a social media platform and online community where registered users can engage in discussions, share content, and participate in various communities called subreddits.

Data from Reddit can be utilized within MindsDB to train AI models and chatbots.

## Prerequisites

Before proceeding, ensure the following prerequisites are met:

1. Install MindsDB [locally via Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or use [MindsDB Cloud](https://cloud.mindsdb.com/).
2. To connect Reddit to MindsDB, install the required dependencies following [this instruction](/setup/self-hosted/docker#install-dependencies).
3. Install or ensure access to Reddit.

## Connection

This handler is implemented using the [PRAW (Python Reddit API Wrapper)](https://praw.readthedocs.io/en/latest/) library, which is a Python package that provides a simple and easy-to-use interface to access the Reddit API.

The required arguments to establish a connection are as follows:

* `client_id` is a Reddit API client ID.
* `client_secret` is a Reddit API client secret.
* `user_agent` is a user agent string to identify your application.

<Tip>
Here is how to get your Reddit credentials:

1. Go to Reddit App Preferences at https://www.reddit.com/prefs/apps or https://old.reddit.com/prefs/apps/
2. Scroll down to the bottom of the page and click *Create another app...*
3. Fill out the form with the name, description, and redirect URL for your app, then click *Create app*
4. Now you should be able to see the personal user script, secret, and name of your app. Store those as environment variables: `CLIENT_ID`, `CLIENT_SECRET`, and `USER_AGENT`, respectively.
</Tip>

In order to make use of this handler and connect the Reddit app to MindsDB, the following syntax can be used:

```sql
CREATE DATABASE my_reddit
WITH 
    ENGINE = 'reddit',
    PARAMETERS = {
     "client_id": "YOUR_CLIENT_ID",
     "client_secret": "YOUR_CLIENT_SECRET",
     "user_agent": "YOUR_USER_AGENT"
    };
```

It creates a database that comes with two tables: `submission` and `comment`.

## Usage

Now you can fetch data from Reddit, like this:

```sql
SELECT *
FROM my_reddit.submission
WHERE subreddit = 'MachineLearning'
AND sort_type = 'top'                   -- specifies the sorting type for the subreddit (possible values include 'hot', 'new', 'top', 'controversial', 'gilded', 'wiki', 'mod', 'rising')
AND items = 5;                          -- specifies the number of items to fetch from the subreddit
```

You can also fetch comments for a particular post/submission, like this:

```sql
SELECT *
FROM my_reddit.comment
WHERE submission_id = '12gls93'
```

<Info>
For more information about available actions and development plans, visit [this page](https://github.com/mindsdb/mindsdb/blob/staging/mindsdb/integrations/handlers/reddit_handler/README.md).
</Info>
